import hashlib
import time

import requests

from application.utils.access_token import redis_access_token
from application.utils.get_api_ticket import redis_api_ticket


class WxCardSign(object):
    def __init__(self):
        self.__data = []

    def add_data(self, data):
        self.__data.append(str(data))

    def get_signature(self):
        self.__data.sort()
        str_to_sign = ''.join(self.__data)
        # print('str_to_sign: ', str_to_sign)
        return hashlib.sha1(str_to_sign.encode('utf-8')).hexdigest()


def get_all_signature(timestamp, yf_code, card_id, nonce_str, api_ticket):
    signer = WxCardSign()
    signer.add_data(yf_code)
    signer.add_data(nonce_str)
    signer.add_data(timestamp)
    signer.add_data(api_ticket)
    signer.add_data(card_id)
    signature = signer.get_signature()
    return signature


if __name__ == '__main__':
    signer = WxCardSign()
    signer.add_data(1231231)
    signer.add_data(int(time.time()))
    signer.add_data("xxxx")
    print(signer.get_signature())
